#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#include<stdio.h>
#include<string.h>

int main() {
	int N;
	char hh;
	scanf("%d", &N);
	scanf("%c", &hh);
	char A[10][10];
	char B[10][10];
	int i, j;

	for (i = 1; i <= N; i++)
	{
		for (j = 1; j <= N; j++)
		{
			scanf("%c", &A[i][j]);
			scanf("%c", &hh );
		}
	}

	for (i = 1; i <= N; i++)
	{
		for (j = 1; j <= N; j++)
		{
			scanf("%c", &B[i][j]);
			scanf("%c", &hh );
		}
	}

	int a = 1;
	int b = 1;
	int c = 1;
	int d = 1;
	for (i = 1; i <= N; i++)
	{
		for (j = 1; j <= N; j++)
		{
			if (B[i][j] != A[N + 1 - j][i])
			{
				a = 0;
			}
			if (B[i][j] != A[j][N + 1 - i])
			{
				b = 0;
			}
			if (B[i][j] != A[N + 1 - i][N + 1 - j])
			{
				c = 0;
			}
			if (B[i][j] != A[i][j])
			{
				d = 0;
			}
		}
	}

	if (a == 1)
	{
		printf("1");
	}
	else if (b == 1)
	{
		printf("2");
	}
	else if (c == 1)
	{
		printf("3");
	}
	else if (d == 1)
	{
		printf("4");
	}
	else
	{
		printf("5");
	}
	return 0;
}